package com.qzsoft.zhjd.common.utils;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@SuppressWarnings({ "rawtypes", "serial" })
public class CountTopData implements Serializable {
    /**
     * 标题
     */
    private List<String> names;

    private List<Map<String,String>> columns;

    public String categoryName="";
    public String title="";

    private Object countDto;

    private boolean firstMerge;

    public Class<?> objClass;

    /**
     * 数据
     */
    private List<Object[]> data;

    /**
     * 统计数据数量
     */
    private int num = 1;

    /**
     * 图片数据
     */
    private List<Map<String,List<Map<String,Object>>>> peiChar = new ArrayList<>();

    /**
     * 柱状图数据
     */
    private List<Map<String,Object>> barChar = new ArrayList<>();

    /**
     * 列表数据
     */
    private List<ExportListData> curlist = new ArrayList<>();

    /**
     * 分页列表数据?
     */
    private List<ExportListData> pageList = new ArrayList<>();

    /**
     * 图例
     */
    private List<Map<String,Object>> lengend = new ArrayList<>();


    public CountTopData(){}
    public CountTopData(List<String> names,List<Object[]> data){
        if(!CollectionUtils.isNotEmpty(names)){
            RenExceptionUtils.throwEx("统计数据的标题不能为空！");
        }else{
            if(ObjectUtils.isEmpty(data)){
                List<Object[]> dd = new ArrayList<>();
                for(int index = 0;index<names.size();index++){
                    Object[] o = new Object[this.num];
                    for(int i = 0;i<o.length;i++){
                        o[i] = 0;
                    }
                    dd.add(o);
                }
                this.data = dd;
            }else{
                if(names.size() == data.size()){
                    this.data = data;
                }else if(data.size() > names.size()){
                    this.data = data.subList(0,names.size());
                }else if(data.size() < names.size()){
                    RenExceptionUtils.throwEx("统计数据为空！");
                }
            }
            this.names = names;
        }

    }
    public CountTopData(List<String> names,List<Object[]> data,int num){
        if(!CollectionUtils.isNotEmpty(names)){
            RenExceptionUtils.throwEx("统计数据的标题不能为空！");
        }else{
            this.num = num;
            this.data = data;
            this.names = names;
        }

    }

    public CountTopData(String categoryName) {
        this.categoryName = categoryName;
    }
}
